/* GUI CONVERTED from rescmt.p (converter v1.76) Wed Jan 23 14:49:44 2002 */
/* rescmt.p - SHOP CALENDAR MAINTENANCE SHIFT ENTRY                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.1.3 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 6.0     LAST MODIFIED: 03/13/90    BY: EMB                 */
/* REVISION: 7.0     LAST MODIFIED: 10/11/91    BY: smm *F230*          */
/* REVISION: 7.0     LAST MODIFIED: 05/05/92    BY: emb *F472*          */
/* REVISION: 7.0     LAST MODIFIED: 05/12/92    BY: emb *F478*          */
/* REVISION: 7.3     LAST MODIFIED: 12/09/92    BY: emb *G468*          */
/* REVISION: 7.3     LAST MODIFIED: 09/01/93    BY: emb *GE99*          */
/* Oracle changes (share-locks)    09/13/94     BY: rwl *FR25*          */
/* REVISION: 7.3     LAST MODIFIED: 10/24/94    BY: ljm *GN54*          */
/* REVISION: 7.5     LAST MODIFIED: 10/24/94    BY: mwd *J034*          */
/* REVISION: 7.0     LAST MODIFIED: 04/24/95    BY: ais *F0P6*          */
/* REVISION: 8.5  LAST MODIFIED: 03/05/97   BY: *G2LB* Jack Rief        */
/* REVISION: 8.5  LAST MODIFIED: 06/24/97   BY: *G2NM* Murli Shastri    */
/* REVISION: 8.5  LAST MODIFIED: 07/03/97   BY: *G2NS* Maryjeane Date   */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0J4* Mudit Mehta      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.3 $    BY: Annasaheb Rahane      DATE: 01/18/02  ECO: *N180*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rescmt_p_1 "Production Line"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_2 "Friday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_3 "Monday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_10 " Shift Adjustments "
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_13 "Saturday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_14 "Wednesday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_16 "Shift 4"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_17 "Shift 3"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_18 "Shift 2"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_19 "Shift 1"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_20 "Thursday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_21 "Sunday"
/* MaxLen: Comment: */

&SCOPED-DEFINE rescmt_p_22 "Tuesday"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable del-yn like mfc_logical initial no.

define new shared variable ii as integer.
define new shared variable mod_shifts like shop_shifts initial no.

define stream hf.
define variable site like shop_site.
define variable wkctr like shop_wkctr.

define new shared variable shft_h_start1 as character format "99:99".
define new shared variable shft_h_start2 as character format "99:99".
define new shared variable shft_h_start3 as character format "99:99".
define new shared variable shft_h_start4 as character format "99:99".
define new shared variable start_time as character.
define new shared variable shop_recno as recid.
define variable disp-shifts as character no-undo.
define variable disp-modify as character no-undo format "x(20)".
define variable colLabel as character no-undo extent 5.

define new shared frame c1.
define new shared frame c2.
define new shared frame c3.
define new shared frame c4.
define new shared frame c5.
define new shared frame c6.
define new shared frame c7.

assign
   disp-shifts = getTermLabel("SHIFTS",8)
   disp-modify = getTermLabel("MODIFY",20).


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
shop_site  colon 25
   shop_wkctr colon 25 label {&rescmt_p_1} ln_desc  no-label
   skip(1)
   disp-shifts at 25 no-label disp-modify at 35 no-label
   skip
   shop_shifts[1] colon 25 label {&rescmt_p_21}    space(5) mod_shifts[1] no-label
   shop_shifts[2] colon 25 label {&rescmt_p_3}    space(5) mod_shifts[2] no-label
   shop_shifts[3] colon 25 label {&rescmt_p_22}   space(5) mod_shifts[3] no-label
   shop_shifts[4] colon 25 label {&rescmt_p_14} space(5) mod_shifts[4] no-label
   shop_shifts[5] colon 25 label {&rescmt_p_20}  space(5) mod_shifts[5] no-label
   shop_shifts[6] colon 25 label {&rescmt_p_2}    space(5) mod_shifts[6] no-label
   shop_shifts[7] colon 25 label {&rescmt_p_13}  space(5) mod_shifts[7] no-label
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{rescfm.i c1 "SUNDAY_SHIFTS"}
{rescfm.i c2 "MONDAY_SHIFTS"}
{rescfm.i c3 "TUESDAY_SHIFTS"}
{rescfm.i c4 "WEDNESDAY_SHIFTS"}
{rescfm.i c5 "THURSDAY_SHIFTS"}
{rescfm.i c6 "FRIDAY_SHIFTS"}
{rescfm.i c7 "SATURDAY_SHIFTS"}

/* DISPLAY */
view frame a.
display disp-shifts disp-modify with frame a.

mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


   mod_shifts = no.
   prompt-for shop_site shop_wkctr
      with frame a
   editing:

      /* FIND NEXT/PREVIOUS RECORD */
      {mfnp05.i shop_cal shop_cal
         "can-find (first shft_det where shft_site = shop_site
           and shft_wkctr = shop_wkctr and shft_mch = shop_mch)"
         shop_site "input shop_site"}

      if recno <> ? then do:
         find ln_mstr no-lock where ln_line = shop_wkctr
            and ln_site = shop_site no-error.
         display
            shop_site
            shop_wkctr
            ln_desc when (available ln_mstr)
            "" when (not available ln_mstr) @ ln_desc
            shop_shifts mod_shifts
         with frame a.
      end.
   end. /* EDITING */

   {gprun.i ""gpsiver.p""
      "(input (input shop_site), input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if return_int = 0 then do:
      {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
      /*USER DOES NOT HAVE ACCESS TO THIS SITE */
      next-prompt shop_site with frame a.
      undo mainloop, retry.
   end.

   do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

      find shop_cal exclusive-lock
      using shop_wkctr and shop_site
      where shop_mch = "" no-error.

      if not available shop_cal
         or not can-find (first shft_det where shft_site = input shop_site
         and shft_wkctr = input shop_wkctr and shft_mch = "")
      then do:
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      end.

      if not available shop_cal then do:
         {mfoutnul.i &stream_name = "hf"}
         find shop_cal no-lock where shop_site = input shop_site
            and shop_wkctr = "" and shop_mch = "" no-error.
         if not available shop_cal then
         find shop_cal no-lock where shop_site = ""
            and shop_wkctr = "" and shop_mch = "" no-error.
         site = input shop_site.
         wkctr = input shop_wkctr.

         do with frame hf:
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame hf:handle).
            if available shop_cal then
               display stream hf shop_cal with frame hf.
            display stream hf site @ shop_site wkctr @ shop_wkctr with frame hf.
            create shop_cal.
            assign shop_cal.
            shop_shifts = no.
         end.
      end.

      if not can-find (first shft_det where shft_site = shop_site
         and shft_wkctr = shop_wkctr and shft_mch = shop_mch)
      then do:
         do ii = 1 to 7:
            find shft_det where shft_mch = shop_mch
               and shft_wkctr = shop_wkctr
               and shft_site = shop_site
               and shft_day = ii no-error.
            if not available shft_det then do:
               if shop_hours[ii] <> 0 then do:
                  shop_shifts[ii] = yes.
                  create shft_det.
                  assign
                     shft_mch   = shop_mch
                     shft_wkctr = shop_wkctr
                     shft_site  = shop_site
                     shft_day   = ii
                     shft_hour1 = shop_hours[ii]
                     shft_load1 = 100
                     shft_load2 = 100
                     shft_load3 = 100
                     shft_load4 = 100.
               end.
            end.
            else do:
               if shop_hours[ii] = 0 then delete shft_det.
               else shop_shifts[ii] = yes.
            end.
         end.
         assign
            mod_shifts[1] = shop_wday[1]
            mod_shifts[2] = shop_wday[2]
            mod_shifts[3] = shop_wday[3]
            mod_shifts[4] = shop_wday[4]
            mod_shifts[5] = shop_wday[5]
            mod_shifts[6] = shop_wday[6]
            mod_shifts[7] = shop_wday[7].
      end.
      else assign mod_shifts = no.
      find ln_mstr no-lock where ln_site = shop_site
         and ln_line = shop_wkctr no-error.
      display shop_site shop_wkctr
         ln_desc when (available ln_mstr)
         "" when (not available ln_mstr) @ ln_desc
         shop_shifts mod_shifts
      with frame a.

      if (shop_wkctr <> "")
         and not available ln_mstr then do:
         {pxmsg.i &MSGNUM=8524 &ERRORLEVEL=2}
      end.

      ststatus = stline[2].
      status input ststatus.

      do on error undo, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

         del-yn = no.
         set mod_shifts
         editing:
            ii = frame-index.
            find shft_det no-lock where shft_mch = shop_mch
               and shft_wkctr = shop_wkctr
               and shft_site = shop_site
               and shft_day = ii no-error.
            if available shft_det then do:
               {gprun.i ""rescmta.p"" "(recid(shft_det),ii)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end.
            else do:
               if ii = 1 then clear frame c1.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c1 = F-c1-title.
               if ii = 2 then clear frame c2.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c2 = F-c2-title.
               if ii = 3 then clear frame c3.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c3 = F-c3-title.
               if ii = 4 then clear frame c4.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c4 = F-c4-title.
               if ii = 5 then clear frame c5.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c5 = F-c5-title.
               if ii = 6 then clear frame c6.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c6 = F-c6-title.
               if ii = 7 then clear frame c7.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c7 = F-c7-title.
               if ii = 1 then view frame c1.
               if ii = 2 then view frame c2.
               if ii = 3 then view frame c3.
               if ii = 4 then view frame c4.
               if ii = 5 then view frame c5.
               if ii = 6 then view frame c6.
               if ii = 7 then view frame c7.
            end.
            readkey.
            if lastkey = keycode("F5")
               or lastkey = keycode("CTRL-D")
            then do:
               del-yn = yes.
               {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
               if not del-yn then undo, retry.
               if del-yn then do:
                  for each shft_det exclusive-lock where shft_mch = shop_mch
                        and shft_wkctr = shop_wkctr
                        and shft_site = shop_site:
                     delete shft_det.
                  end.
                  shop_shifts = no.
                  if shop_wkctr > ""
                     and not can-find(wc_mstr where wc_wkctr = shop_wkctr
                     and wc_mch = shop_mch)
                  then do:
                     for each cal_det exclusive-lock where cal_site = shop_site
                           and cal_wkctr = shop_wkctr
                           and cal_mch = shop_mch:
                        delete cal_det.
                     end.
                     delete shop_cal.
                  end.
                  clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
                  del-yn = no.
                  next mainloop.
               end.
            end.
            apply lastkey.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if available shop_cal
      then shop_recno = recid(shop_cal).
   else shop_recno = ?.

   {gprun.i ""rescmtb.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   repeat ii = 1 to 7:
      display shop_shifts[ii] with frame a.
   end.

   FORM /*GUI*/ 
      
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
cal_ref   colon 15
      cal_start colon 32
      cal_shift1 label {&rescmt_p_19} colon 55
      cal_end   colon 32
      cal_shift2 label {&rescmt_p_18} colon 55
      cal_shift3 label {&rescmt_p_17} colon 55
      cal_shift4 label {&rescmt_p_16} colon 55
    SKIP(.4)  /*GUI*/
with frame b width 80 
      attr-space side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER.
 F-b-title = (getFrameTitle("SHIFT_ADJUSTMENTS",25)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame b =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame b + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5. /*GUI*/


   /* SET EXTERNAL LABELS */
   setFrameLabels(frame b:handle).

   repeat with frame b:
/*GUI*/ if global-beam-me-up then undo, leave.

      prompt-for cal_ref cal_start with frame b editing:
         /* FIND NEXT/PREVIOUS RECORD */
         {mfnp05.i cal_det cal_det
            "cal_site = shop_site
            and cal_wkctr = shop_wkctr
            and cal_mch = shop_mch"
            cal_ref "input cal_ref"}

         if recno <> ? then
         display cal_ref cal_start cal_end
            cal_shift1 cal_shift2 cal_shift3 cal_shift4.
      end.

      /* ADD/MOD/DELETE */
      find first cal_det using cal_ref and cal_start
      where cal_site = shop_site
      and cal_wkctr = shop_wkctr
      and cal_mch = shop_mch no-error.
      if not available cal_det then do:
         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         create cal_det.
         assign
            cal_ref
            cal_start
            cal_site  = shop_site
            cal_wkctr = shop_wkctr
            cal_mch = shop_mch.
      end.
      recno = recid(cal_det).

      display cal_ref cal_start cal_end
         cal_shift1 cal_shift2 cal_shift3 cal_shift4.

      ststatus = stline[2].
      status input ststatus.

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         del-yn = no.
         set  cal_end cal_shift1 cal_shift2 cal_shift3 cal_shift4
            go-on ("F5" "CTRL-D" ).
         if lastkey = keycode("F5")
            or lastkey = keycode("CTRL-D") then do:
            del-yn = yes.
            {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
            if not del-yn then undo, retry.
            if del-yn then do:
               delete cal_det.
               clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
               del-yn = no.
            end.
         end.
         else cal_hours = cal_shift1 + cal_shift2 + cal_shift3 + cal_shift4.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.

   clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
end.
/*GUI*/ if global-beam-me-up then undo, leave.

status input.
